/*
* 平仓子表格
*/
import React, { Component, PropTypes } from 'react';
import { Table, Row, Col, Spin } from 'antd';
import moment from 'moment';
import dicts from '../dicts';
import api from '../../../api';
import OrderDetail from '../OrderDetail';

class CloseOrderDetail extends Component {
	static propTypes = {
		detail: PropTypes.object,
	}
	state = {
		data: undefined,
	}
	componentDidMount() {
		this.getData(this.props);
	}
	componentWillReceiveProps(nextProps) {
		if (nextProps !== this.props && nextProps.detail != this.props.detail) {
			this.getData(nextProps);
		}
	}
	getData({ detail: { trader, closeOrderId, openOrderId } }) {
		api.getCloseOrder({ trader, orderId: closeOrderId }).then((response) => {
			this.setState({ data: {
				...this.state.data,
				...response.data,
			} });
		});
		api.getCommentClosedPos({ trader, closeOrderId, openOrderId }).then((response) => {
			this.setState({ data: {
				...this.state.data,
				comment: {
					...response.data,
				}
			} });
		});
	}
	render() {
		const { data } = this.state;
    const orderDetailProps = {
      openOrderId: this.props.detail.openOrderId,
      closeOrderId: this.props.detail.closeOrderId,
      closeOrder: this.props.detail.data,
    };
		return (
			<OrderDetail data={data} {...orderDetailProps} />
		);
	}
}

export default CloseOrderDetail;

